#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import division

class RealSettings:
    def __init__(self, yRealMax = 0, yRealMin = 0, xRealWidth = 0, xRealStep = 0, yRealStep = 0):
        self.yRealMax = yRealMax
        self.yRealMin = yRealMin
        self.xRealWidth = xRealWidth
        self.xRealStep = xRealStep
        self.yRealStep = yRealStep

class RealKoeffs:
    def __init__(self, kxRtoS = 1.0, kyRtoS = 1.0):
        self.kxRtoS = kxRtoS # x: Sample to Real
        self.kyRtoS = kyRtoS # y: Sample to Real


class SampleSettings:
    def __init__(self, ySampleMin, ySampleMax, xSampleWidth):
        self.ySampleMin, self.ySampleMax, self.xSampleWidth = (
        ySampleMin, ySampleMax, xSampleWidth)

class Grid:
    def __init__(self, realSettings, realKoeffs):
        self.realSettings = realSettings
        self.realKoeffs = realKoeffs
        self.calc_settings(realSettings, realKoeffs)

    def calc_settings(self, realSettings, realKoeffs):
        self.xSampleWidth = int(realSettings.xRealWidth * realKoeffs.kxRtoS)
        self.ySampleMin = int(realSettings.yRealMin * realKoeffs.kyRtoS)
        self.ySampleMax = int(realSettings.yRealMax * realKoeffs.kyRtoS)
        self.xSampleStep = int(realSettings.xRealStep * realKoeffs.kxRtoS)
        self.ySampleStep = int(realSettings.yRealStep * realKoeffs.kyRtoS)

    def set_koeffs(self, realKoeffs):
        self.realKoeffs = realKoeffs
        self.calc_settings(self.realSettings, self.realKoeffs)

    def get_koeffs(self):
        return self.realKoeffs

    def get_real_settings(self):
        return self.realSettings

    def set_real_settings(self, realSettings):
        self.realSettings = realSettings
        self.calc_settings(self.realSettings, self.realKoeffs)

    def get_x_sample_width(self):
        return self.xSampleWidth

    def get_sample_settings(self):
        return SampleSettings(self.ySampleMin, self.ySampleMax, self.xSampleWidth)

    def draw(self, drawer, lastTime):
        xSteps = self.xSampleWidth // self.xSampleStep
        for x in xrange(xSteps):
            currentX = self.xSampleStep*x
            drawer.draw_x_axis_text(str(lastTime - self.realSettings.xRealStep * x),
                    currentX)
            if x: drawer.draw_x_axis_net(currentX)

        ySteps = abs((self.ySampleMax) // self.ySampleStep) + 1
        for y in xrange(ySteps):
            drawer.draw_y_axis_text(str(self.realSettings.yRealStep * y),  self.ySampleStep*y)
            drawer.draw_y_axis_net(self.ySampleStep*y)
        drawer.draw_y_axis_text(str(self.realSettings.yRealMax),  self.ySampleMax)

        ySteps = abs((self.ySampleMin) // self.ySampleStep)
        for y in xrange(1, ySteps, 1):
            drawer.draw_y_axis_text(str(- self.realSettings.yRealStep * y),  -self.ySampleStep*y)
            drawer.draw_y_axis_net(-self.ySampleStep*y)
        drawer.draw_y_axis_text(str(self.realSettings.yRealMin),  self.ySampleMin)

if __name__ == "__main__":
    execfile("test_grid.py")